<template>
	<div class="child">
		<h3>子组件</h3>
		<h2>这是儿子的玩具:{{ toy }}</h2>
		<button @click="sendToy"> 给父组件传递玩具</button>
	</div>
</template>

<script setup lang="ts" name="Child">
import { ref } from 'vue';


let toy = ref('奥特曼')
// 还得在子组件中先声明事件
const emit = defineEmits(['send-toy'])

function sendToy() {
	console.log('@@@@@ 发送玩具',toy)
	//自定义事件
	emit('send-toy', toy)
}

</script>

<style scoped>
.child {
	margin-top: 10px;
	background-color: rgb(76, 209, 76);
	padding: 10px;
	box-shadow: 0 0 10px black;
	border-radius: 10px;
}
</style>